const express = require('express')
const router = express.Router()
const { registValidator, loginValidator, updateValidator } = require('../middleware/validator/user')
/**登录验证 */
const { jwtValidator } = require('../middleware/jsonwebtoken/index')
//操作的中间件
const userController = require('../controller/userController')
//引入文件上传插件 此处只允许使用formdata的形式上传文件
const multer = require('multer')
const upload = multer({
    dest: 'public/',
    limits: {
        fileSize: 100000  // 限制文件大小为100KB，单位为字节
    }
})

router
//用户的注册
.post('/regist', registValidator, userController.registe)
//用户登录
.post('/login', loginValidator, userController.login)
//用户信息的更新
.put('/update', jwtValidator(), updateValidator, userController.update)
//上传用户头像
.post('/headimage', jwtValidator(), upload.single('headimage'), userController.headimage)
//获取用户的列表
.get('/list', jwtValidator(), userController.list)
//频道的订阅
.get('/subscribe/:userId',jwtValidator(),userController.subscribe)
//取消频道的订阅
.get('/unsubscribe/:userId',jwtValidator(),userController.unsubscribe)
//获取频道信息
.get('/getuser/:userId',jwtValidator(),userController.getuser)
//获取粉丝的人
.get('/getchannel',jwtValidator(),userController.getchannel)
//查看关注的人
.get('/getsubscribe/:userId',userController.getsubscribe)
module.exports = router